#!/bin/bash

# 检查是否提供了目录参数
if [ "$#" -ne 1 ]; then
    echo "Usage: $0 <directory>"
    exit 1
fi

# 从命令行参数获取目录路径
TARGET_DIR="$1"

# 检查目录是否存在
if [ ! -d "$TARGET_DIR" ]; then
    echo "Error: Directory does not exist."
    exit 1
fi

# 进入指定目录
cd "$TARGET_DIR"

# 查找并删除以._开头的文件
find . -type f -name "._*" -exec rm -f {} \;

# 查找并删除以._开头的目录
find . -type d -name "._*" -exec rm -rf {} \;

echo "Deletion of files and directories starting with ._ in $TARGET_DIR completed."
